import { _decorator, Component, Node, RichText } from 'cc';
import { ParamUI } from './ParamUI';
import UiManager from './UiManager';
import { plog } from '../Utils/Tools';
const { ccclass, property } = _decorator;

@ccclass('MsgBox')
export class MsgBox extends Component {
    @property(Node)
    BtnOk: Node = null;
    @property(Node)
    BtnCancel: Node = null;
    @property(RichText)
    Content: RichText = null;

    onLoad(): void {
        let pu = this.node.getComponent(ParamUI)
        pu.RegisterCallbackOpen("-", (pm) => {
            this.Content.string = pm.label
        })
        this.BtnOk.on("click", this.onBtnOk, this);
        this.BtnCancel.on("click", this.onBtnCancel, this);
        this.node.on(Node.EventType.TOUCH_END, this.onBtnBack, this);
    }
    onBtnOk() {
        UiManager.Instance.RemoveUI(this.node, true)
    }
    onBtnCancel() {
        UiManager.Instance.RemoveUI(this.node, false)
    }
    onBtnBack(evt) {
        evt.bubbles = false
    }

    onDestroy() {
        this.BtnOk.off("click", this.onBtnOk, this);
        this.BtnCancel.off("click", this.onBtnCancel, this);
        this.node.off(Node.EventType.TOUCH_END, this.onBtnBack, this);
    }

    start() {

    }
    update(deltaTime: number) {

    }
}


